<?php
namespace app\controller;

use app\BaseController;
use \think\facade\Request;
use \think\facade\Db;
class UplodeFile extends BaseController
{
  
  
  // h5把图片上传到本地
  public function uplodeImageLocalH5(Request $request)
  {
     
	  $params = Request::param();
	  $file = request()->file("file");
	  
	  //文件名称
	  $img_name = $file->getOriginalName();
	  // 把上传的excel文件下载到本地一份
	  $savename = \think\facade\Filesystem::disk('public')->putFile('file', $file);
	  $img_url = str_replace("\\","/",$savename);
	  return $this->returnJson(200,'操作成功',['img_url'=>$img_url]);
  }
  // 删除图片
  public function delH5Img()
  {
	  $params = Request::param();
	  Db::name('check_picture')
	  	->where('id',$params['id'])
	  	->useSoftDelete('delete_time',time())
	  	->delete();
	$this->returnJson(200,'',[]); 	
  }

  
  //pc把图片上传到本地
  public function uplodeImageLocal(Request $request)
  {
     $params = Request::param();
	 $cid = $params['cid'];
     $file = request()->file("file");
	 //验证图片格式
	 $originalExtension = $file->getOriginalExtension();
	 $arr = ['jpg','png'];
	 // if(!in_array($originalExtension,$arr)){
		// return $this->returnJson(400,'文件格式错误',[]);
	 // }
	 
	 //文件名称
	 $img_name = $file->getOriginalName();
	
	 // 把上传的excel文件下载到本地一份
	 $savename = \think\facade\Filesystem::disk('public')->putFile('file', $file);
	 $img_url = str_replace("\\","/",$savename);
	
	 
	 $dd = [
		 'img_url'=>$img_url,
		 'add_time'=>date("Y-m-d H:i:s"),
		 'img_name'=>$img_name,
		 'savename'=>$savename,
	 ];
     Db::table('img_sys')->insert($dd);
	 return $this->returnJson(200,'操作成功',['img_url'=>$img_url]);
	
  }
 
  
}